<?php
	session_start();
	session_destroy(); 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Lock of Han Seok-bong - User Register page</title>
		<script src="./Scripts/jquery-1.10.2.min.js"></script>
		<style type="text/css" media="screen">
			body {
				background-color: #EBEBEB;
				width: 900px
				margin: 0 auto;
				text-align: center;
			}
			#table_singup {
				margin: 0 auto;	
			}
		</style>
	</head>
	<body>
		<h1>Fill out following form to sign up</h1>
			<table id="table_singup" border="0">
				<tr>
					<td>ID</td>
					<td><input class="input_data" id="input_id" type="text"/></td>
				</tr>
				<tr>
					<td>PASSWORD</td>
					<td><input class="input_data" id="input_password" type="password"/></td>
				</tr>
				<tr>
					<td>PASSWORD*</td>
					<td><input class="input_data" id="input_password_confirm" type="password"/></td>
				</tr>
				<tr>
					<td>PHONE NUMBER</td>
					<td><input class="input_data" id="input_phone_num" type="text"/></td>
				</tr>
				<tr>
					<td><button id="btn_user_register">SIGN UP</button></td>
					<td><button id="btn_table_reset">RESET</button></td>
				</tr>
			</table>
	</body>
	<script>
		$(document).ready(function(){
			$('#btn_user_register').click(function(){
				if( !($('#input_id').val().length > 0) 
				|| !($('#input_password').val().length > 0) 
				|| !($('#input_password_confirm').val().length > 0)){
					alert("Form is empty.");
				};
				if(!($('#input_password').val() == $('#input_password_confirm').val())){
					alert("Make sure your password.");
				};
				$.ajax({
					url: "./Action/register.php",
					type: "POST",
					data: { reg_id : $('#input_id').val(), 
							reg_password : $('#input_password').val(),
							reg_phone_num : $('#input_phone_num').val() },
					dataType: "html" //반환되는 데이터의 타입을 의미한다.
				}).done(function(msg){
					msg = $.trim(msg);
					if(msg=="success"){
						alert("Succes to register!");
						$(location).attr("href","./index.php");
					}else{ alert("Sorry. fail to register"); }
				});
			});
			$('#btn_table_reset').click(function(){
				$('.input_data').val("");
			});
		});
	</script>
</html>